package net.oschina.app.adapter.general;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseListAdapter;
import net.oschina.app.base.Global;
import net.oschina.app.bean2.GeneralNewsBean;

import net.oschina.app.ui.activity.general.HotWebActivity;


import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Shinelon on 2017/1/15.
 */

public class HotListAdapter extends BaseListAdapter<List<GeneralNewsBean.NewsBean>> {

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(Global.mContext).inflate(R.layout.item_general, parent, false);
        NewsHolder holder = new NewsHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        GeneralNewsBean.NewsBean data = (GeneralNewsBean.NewsBean) mList.get(position);
        ((NewsHolder) holder).setData(data);
        ((NewsHolder) holder).mIv.setVisibility(View.GONE);
        ((NewsHolder) holder).mTvTitle.setText(data.getTitle());
        ((NewsHolder) holder).mTvBody.setText(data.getBody());
        ((NewsHolder) holder).mTvAuthor.setText(data.getAuthor());
        ((NewsHolder) holder).mTvCount.setText(data.getCommentCount()+"");
    }

    class NewsHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_title)
        TextView mTvTitle;
        @BindView(R.id.tv_body)
        TextView mTvBody;
        @BindView(R.id.tv_author)
        TextView mTvAuthor;
        @BindView(R.id.tv_date)
        TextView mTvDate;
        @BindView(R.id.tv_count)
        TextView mTvCount;
        @BindView(R.id.iv_original)
        ImageView mIv;

        public NewsHolder(final View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void setData(GeneralNewsBean.NewsBean data) {
            if (data!=null) {
                setOnItemClick(itemView,Global.mContext
                        , HotWebActivity.class,String.valueOf(data.getId()));
            }
        }
    }
}
